import sys
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMenuBar, QMenu, QAction, QApplication


class CustomMenu(QMenuBar):
    window_index = QtCore.pyqtSignal(int, int, int)

    def __init__(self):
        super().__init__()
        self.file_menu = self.addMenu('文件')

        # 创建动作action到文件菜单栏
        self.new_action = QAction('新建', self)
        self.new_action.setShortcut('Ctrl+N')
        self.new_action.setStatusTip('新建文件')
        self.new_action.triggered.connect(self.new_file)
        self.file_menu.addAction(self.new_action)

        # 创建打开动作并添加到文件菜单
        self.open_action = QAction('打开', self)
        self.open_action.setShortcut('Ctrl+O')
        self.open_action.setStatusTip('打开文件')
        self.open_action.triggered.connect(self.open_file)
        self.file_menu.addAction(self.open_action)

        self.picture_ocr = self.addMenu('图片识别')
        self.car_action = QAction("车牌识别", self)
        self.car_action.triggered.connect(lambda: self.go_to_window(2, 1280, 960))
        self.face_menu = QMenu('人脸功能', self)
        self.face_input = QAction('人脸录入', self)
        self.face_many_input = QAction('人脸批量录入', self)
        self.face_identify = QAction('人脸识别', self)
        self.face_menu.addAction(self.face_input)
        self.face_menu.addAction(self.face_many_input)
        self.face_menu.addAction(self.face_identify)
        self.face_input.triggered.connect(lambda: self.go_to_window(3))
        self.face_identify.triggered.connect(lambda: self.go_to_window(4))
        self.face_many_input.triggered.connect(lambda: self.go_to_window(5))
        self.picture_ocr.addAction(self.car_action)
        self.picture_ocr.addMenu(self.face_menu)

        # 创建动作action到文件菜单栏
        self.zyy_menu = self.addMenu('API和数据库查询')
        self.start_click = QAction('菜谱API查询', self)
        self.start_click.setShortcut('Ctrl+S')
        self.start_click.setStatusTip('开始连点任务')
        self.start_click.triggered.connect(lambda: self.go_to_window(6))
        self.zyy_menu.addAction(self.start_click)


        self.end_click = QAction('数据库查询', self)
        self.end_click.setShortcut('Ctrl+E')
        self.end_click.setStatusTip('停止连点任务')
        self.end_click.triggered.connect(lambda: self.go_to_window(7))
        self.zyy_menu.addAction(self.end_click)


    def go_to_window(self, index=0, width=1280, height=960):
        """
        跳转窗口函数
        :param index: 窗口索引，从0开始
        :param width: 窗口宽度
        :param height: 窗口高度
        :return: 无返回值
        """
        self.window_index.emit(index, width, height)

    def new_file(self):
        print('新建文件')

    def open_file(self):
        print('新建文件')
